﻿namespace Iesi.Collections.Generic
{
    using System;
    using System.Collections;
    using System.Collections.Generic;

    [Serializable]
    public abstract class DictionarySet<T> : Set<T>
    {
        protected IDictionary<T, object> InternalDictionary;
        private static readonly object PlaceholderObject;

        static DictionarySet()
        {
            DictionarySet<T>.PlaceholderObject = new object();
        }

        protected DictionarySet()
        {
        }

        public override bool Add(T o)
        {
            if (this.InternalDictionary.ContainsKey(o))
            {
                return false;
            }
            this.InternalDictionary.Add(o, DictionarySet<T>.PlaceholderObject);
            return true;
        }

        public override bool AddAll(ICollection<T> c)
        {
            bool flag = false;
            foreach (T local in c)
            {
                flag |= this.Add(local);
            }
            return flag;
        }

        public override void Clear()
        {
            this.InternalDictionary.Clear();
        }

        public override bool Contains(T o)
        {
            return this.InternalDictionary.ContainsKey(o);
        }

        public override bool ContainsAll(ICollection<T> c)
        {
            foreach (T local in c)
            {
                if (!this.Contains(local))
                {
                    return false;
                }
            }
            return true;
        }

        public override void CopyTo(T[] array, int index)
        {
            this.InternalDictionary.Keys.CopyTo(array, index);
        }

        public override IEnumerator<T> GetEnumerator()
        {
            return this.InternalDictionary.Keys.GetEnumerator();
        }

        protected override void NonGenericCopyTo(Array array, int index)
        {
            ((ICollection) this.InternalDictionary.Keys).CopyTo(array, index);
        }

        public override bool Remove(T o)
        {
            bool flag = this.Contains(o);
            if (flag)
            {
                this.InternalDictionary.Remove(o);
            }
            return flag;
        }

        public override bool RemoveAll(ICollection<T> c)
        {
            bool flag = false;
            foreach (T local in c)
            {
                flag |= this.Remove(local);
            }
            return flag;
        }

        public override bool RetainAll(ICollection<T> c)
        {
            Set<T> set = new HashedSet<T>(c);
            Set<T> set2 = new HashedSet<T>();
            foreach (T local in this)
            {
                if (!set.Contains(local))
                {
                    set2.Add(local);
                }
            }
            return this.RemoveAll(set2);
        }

        public override int Count
        {
            get
            {
                return this.InternalDictionary.Count;
            }
        }

        public override bool IsEmpty
        {
            get
            {
                return (this.InternalDictionary.Count == 0);
            }
        }

        public override bool IsReadOnly
        {
            get
            {
                return this.InternalDictionary.IsReadOnly;
            }
        }

        public override bool IsSynchronized
        {
            get
            {
                return false;
            }
        }

        protected object Placeholder
        {
            get
            {
                return DictionarySet<T>.PlaceholderObject;
            }
        }

        public override object SyncRoot
        {
            get
            {
                return ((ICollection) this.InternalDictionary).SyncRoot;
            }
        }
    }
}

